Xi-Language Reference: Linear Algebra
- determ (Calculates the determinant of a square matrix)
- eigenvalue (Calculates the eigenvalues of a square matrix)
- eigenvector (Calculates the eigenvectors of a square matrix)
- invert (Calculates the inerse of a square matrix)
- linear_solve (Solves a system of linear equations)
- lu (Calculates the LU decomposition of a matrix)
- lu_invert (Second method to invert a matrix)
- prime_factors (computes the prime factors of an integer)
- qr (Calculates the QR factorization of a matrix)
- rcond (Estimates the reciprocal of a condition number of a matrix)
- rcond_inf (Estimates the reciprocal of a condition number of a matrix)
- svd (Calculates the singular value decomposition of a matrix)
- svd_back_sub (Back substitution to solve a system of linear equations)
- transform (transposes the input array)
Parameters
determ ( matrix )
Types: matrix double[]/complex[]
Return
double/complex (the determinant of the matrix)
Description
The function determ computes the determinant of a sqaure
real or complex matrix using LU decomposition.
Example
>print(determ(dincarr(2,2)));
<double> -2
Reference
This function is based on the subroutines dgetrf and zgetrf of
LAPACK.
* -- LAPACK routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
Parameters
eigenvalue ( matrix )
Types: matrix double[]/complex[]
Return
complex[] (eigenvalues of the matrix)
Description
eigenvalue performs a QR decomposition of the square matrix to
obtain the eigenvalues of a matrix.
Example
>print(eigenvalue(dincarr(2,2)))
<cpxarr>
( 3.561552813, 0) (-0.5615528128, 0)
Reference
This function is based on the subroutines dgeev and zgeev of
LAPACK.
* -- LAPACK driver routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
Parameters
eigenvector ( matrix )
Types: matrix double[]/complex[]
Return
double[]/complex[] (eigenvectors of the matrix)
Description
eigenvector performs a QR decomposition of the matrix to
get the eigenvectors of a square matrix. The return value is a matrix.
The eigenvectors are stored in the columns of the return matrix.
The computed eigenvectors are normalized to have Euclidean norm equal to 1.
Example
>print(eigenvector(dincarr(2,2)));
<dblarr>
0.2703230127 -0.8719282093
0.9627696863 0.4896337385
Reference
This function is based on the subroutines dgeev and zgeev of
LAPACK.
* -- LAPACK driver routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
Parameters
invert ( matrix )
Types: matrix double[]/complex[]
Return
double[]/complex[] (inverse of the matrix)
Description
This function computes the inverse of a matrix using the LU
factorization.
Example
( 1)>print(invert(dincarr(2,2)));
<dblarr>
-1.5 0.5
1 0
( 2)>print(invert(dincarr(2,2))#dincarr(2,2));
<dblarr>
1 0
0 1
Reference
This function is based on the subroutines dgetrf and zgetrf of
LAPACK.
* -- LAPACK routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
Parameters
linear_solve ( A, b )
Types: A double[]/complex[]
b double[]/complex[]
Return
double[]/complex[] (solution to linear equations Ax=b)
Description
linear_solve computes the solution to a system of
linear equations. The algorithm is LU decomposition with partial pivoting
and row interchanges.
Example
>print(linear_solve(dincarr(2,2),{1,2}))
<dblarr>
-0.5 1
See also
lu
Reference
This function is based on the subroutines dgesv and zgesv of
LAPACK.
* -- LAPACK driver routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* March 31, 1993
Parameters
lu ( matrix )
Types: matrix double[]/complex[]
Return
[double[]/complex[],int[]] (LU factorization, pivot indices)
Description
lu computes an LU factorization of a real or complex matrix
using partial pivoting with row interchanges. The factors L and U are
stored in the lower und upper part of the first return value. The
unit diagonal elements of L are not stored. The second return value
is the vector of pivot indices. This vector is needed in the call to
lu_invert
Example
>[LU, pivot]=lu(dincarr(2,2));
>print(LU,pivot);
<dblarr>
2 3
0 1
<intarr>
2 2
See also
lu_invert
Reference
This function is based on the subroutines dgetrf and zgetrf of
LAPACK.
* -- LAPACK routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* March 31, 1993
Parameters
lu_invert ( lu, pivot )
Types: lu double[]/complex[]
pivot int[]
Return
double[]/complex[] (inverse of the matrix to lu)
Description
If a matrix was decomposed by the function lu the inverse can
be computed with lu_invert. The function
invert is based on the same algorithm.
Example
>[LU, pivot]=lu(dincarr(2,2));
>print(lu_invert(LU, pivot));
<dblarr>
-1.5 0.5
1 0
See also
lu,
invert
Reference
This function is based on the subroutines dgetri and zgetri of
LAPACK.
* -- LAPACK routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
Parameters
prime_factors ( Number )
Types: Number int
Return
[int[],int[]] ( first array are the prime factors, second array are the power of the prime factors)
Description
The function prime_factors computes the prime factors of an integer.
Example
>[f, p]=prime_factors(45639);
>print(f,p);
<intarr>
461 11 3
<intarr>
1 1 2
>print(461*11*pow(3,2));
Parameters
qr ( matrix )
Types: matrix double[]/complex[]
Return
[double[]/complex[],double[]/complex[]] (QR matrices)
Description
The function qr performs a QR factorization of a real or complex
matrix. The elements on and obove the diagonal of the first return value
(matrix) contain the upper trapezoidal matrix R,the elements below the
diagonal, with the second return value (vector), represent the orthogonal
matrix Q as a product of elementary reflectors.
The matrix Q is represented as a product of elementary reflectors.
Q = H[1] H[2] . . . H[k].
Each H[i] has the form H[i] = I - tau[i] * v * v'
where tau[i] is the second return value, and v is a vector with
v[1:i-1] = 0 and v[i] = 1; v[i+1:m] is stored in the first return value.
Example
>[qr, tau]=qr(dincarr(2,2));
>print(qr,tau)
<dblarr>
1 0
<dblarr>
-2 -3
1 -1
Reference
This function is based on the subroutines dgeqrf and zgeqrf of
LAPACK.
* -- LAPACK routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
Parameters
rcond ( matrix )
Types: matrix double[]/complex[]
Return
double/complex (reciprocal of the condition number)
Description
rcond returns the reciprocal of the condition number of a real
or complex matrix in 1-norm, using the LU factorization. To compute
this number an estimate is obtained for norm(inv(A)).
Example
>print(rcond(dincarr(2,2)));
<double> 0.1
Reference
This function is based on the subroutines dgecon and zgecon of
LAPACK.
* -- LAPACK routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* February 29, 1992
Parameters
rcond_inf ( matrix )
Types: matrix double[]/complex[]
Return
double/complex (reciprocal of the condition number)
Description
rcond returns the reciprocal of the condition number of a real
or complex matrix in the infinity-norm, using the LU factorization.
To compute this number an estimate is obtained for norm(inv(A)).
Example
>print(rcond_inf(dincarr(2,2)));
<double> 0.1
Reference
This function is based on the subroutines dgecon and zgecon of
LAPACK.
* -- LAPACK routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* February 29, 1992
Parameters
svd ( matrix )
Types: matrix double[]/complex[]
Return
[double[]/complex[],double[]/complex[],double[]/complex[]]
Description
svd computes the singular value decomposition of a real or complex
M-by-N matrix A.
A = u * w * vt
The first return value is a vector containing the singular values of A, the
second is an M-by-M orthogonal matrix and the thrirdis an N-by-N
orthogonal matrix. The first min(m,n) columns of second and the rows of the
third return matrix are the left and right singular vectors of A.
Example
>[w,u,vt]=svd(dincarr(2,2));
>print(w,u,vt)
<dblarr>
3.702459174 0.5401815135
<dblarr>
-0.2297529205 0.9732489895
-0.9732489895 -0.2297529205
<dblarr>
-0.5257311121 -0.8506508084
-0.8506508084 0.5257311121
See also
svd_back_sub
Reference
This function is based on the subroutines dgesvd and zgesvd of
LAPACK.
* -- LAPACK driver routine (version 2.0) --
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
* Courant Institute, Argonne National Lab, and Rice University
* September 30, 1994
Parameters
svd_back_sub ( w, u, vt, b )
Types: w double[]/complex[]
u double[]/complex[]
vt double[]/complex[]
b double[]/complex[]
Return
double[]/complex[] (solution of (u*w*vt) * x = b)
Description
This function performs a back substitution to solve a system of
linear equations. SVD is a useful technique to manage a system of
equations (matrices) that are nearly singular. A typical use is
Example
>a={{2.0,2.5,2.5},{2,2.5,2.5},{1.6,-0.4,2.8},{2,-0.5,0.5},{1.2,-0.3,-2.9}}
>b={1.0,1.0,0.6,0.0,-0.8}
>[w,u,vt]=svd(a)
>w[where(w < 1e-10)]=0.0;
>x=svd_back_sub(w,u,vt,b);
>print(a#x);
<dblarr>
1 1 0.6 1.45716772e-16 -0.8
See also
svd
Parameters
transform ( A, b )
Types: A double[]/complex[]
b double[]/complex[]
Return
double[]/complex[] (the transposed matrix)
Description
*Example:
>a={{1, 2} , {3, 4}};
>print(a,transpose(a));
<intarr>
1 2
3 4
<intarr>
1 3
2 4
© 1995 by Bodo Junglas, Klaus Spanderen and Fabian Weis
- Last revised: Wed Jun 19 16:58:32 1996